Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class HexagonGradientBrush


    Private Sub HexagonGradientBrush_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Const fSide = 50
        Dim cx As Integer = Me.Width
        Dim cy As Integer = Me.Height

        'Error: Converting Properties 
        ' Ñònh nghóa nöûa chieàu cao cuûa hình luïc giaùc
        Dim fHalf As Single = fSide * CType(Math.Sin(Math.PI / 3), Single)

        'Ñònh nghóa hình luïc giaùc 
        Dim aptf As PointF()= {New PointF(fSide,         0), _           
                           New PointF(fSide * 1.5f,  0), _
                           New PointF(fSide,         0), _          
                           New PointF(fSide / 2,    -fHalf), _
                           New PointF(-fSide / 2,    -fHalf), _
                           New PointF(-fSide,         0), _
                           New PointF(-fSide * 1.5f,  0), _
                           New PointF(-fSide,         0), _
                           New PointF(-fSide / 2,     fHalf), _     
                           New PointF(fSide / 2,     fHalf) }


        'Taïo choåi veõ thöù nhaát
        Dim pgbrush1 As New PathGradientBrush(aptf, WrapMode.Tile)

        ' Ñònh nghóa choåi veõ thöù hai
        Dim i As Integer
        For i = 0 To aptf.Length - 1 Step i + 1
            aptf(i).X += fSide * 1.5F
            aptf(i).Y += fHalf
        Next
          Dim pgbrush2 = New PathGradientBrush(aptf, WrapMode.Tile)

        e.Graphics.FillRectangle(pgbrush1, 0, 0, cx, cy)
        e.Graphics.FillRectangle(pgbrush2, 0, 0, cx, cy)
    End Sub
End Class